//
//  DesignerListCell.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/19.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "DesignerListCell.h"

#import "StarView.h"

@interface DesignerListCell ()

@property (nonatomic, strong) UIImageView *headImage;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *distanceLabel;
@property (nonatomic, strong) UIButton *connectBtn;
@property (nonatomic,strong)  YYStarView *starView1;
@property (nonatomic,strong)  YYStarView *starView2;
@property (nonatomic,strong)  YYStarView *starView3;

@end

@implementation DesignerListCell

+ (DesignerListCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"DesignerListCell";
    DesignerListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[DesignerListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    self.headImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(80), ScreenX375(80))];
    self.headImage.layer.cornerRadius = ScreenX375(40);
    self.headImage.clipsToBounds = YES;
    [self addSubview:self.headImage];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(104), ScreenX375(15), ScreenX375(35), ScreenX375(18))];
    self.nameLabel.font = Kfont(14);
    self.nameLabel.textColor = REXADECIMALCOLOR(@"#333333");
    [self addSubview:self.nameLabel];
    
    self.distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(142), ScreenX375(17), ScreenX375(50), ScreenX375(15))];
    self.distanceLabel.textColor = REXADECIMALCOLOR(@"#999999");
    self.distanceLabel.font = Kfont(12);
    [self addSubview:self.distanceLabel];
    
    NSArray *noteArr = @[@"等级：",@"信用：",@"好评："];
    for (int i = 0; i < noteArr.count; i++) {
        UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(104), ScreenX375(37) + i * ScreenX375(22), ScreenX375(40), ScreenX375(16))];
        noteLabel.text = noteArr[i];
        noteLabel.textColor = REXADECIMALCOLOR(@"#999999");
        noteLabel.font = Kfont(12);
        [self addSubview:noteLabel];
        
        StarView *starView = [StarView starViewInitWithStarScore:3];
        starView.frame = CGRectMake(ScreenX375(140), ScreenX375(39) + i * ScreenX375(22), 80, ScreenX375(12));
        starView.starSpacing = 5;
        if (i == 0) {
            _starView1 = starView;
        }else if (i == 1) {
            _starView2 = starView;
        }else if (i == 2) {
            _starView3 = starView;
            _starView3.starScore = 5;
        }
        [self addSubview:starView];
    }
    
    self.connectBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(268), ScreenX375(41), ScreenX375(94), ScreenX375(30))];
    [self.connectBtn setTitle:@"在线联系" forState:UIControlStateNormal];
    [self.connectBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.connectBtn.titleLabel.font = Kfont(12);
    self.connectBtn.backgroundColor = ThemeColor;
    self.connectBtn.layer.cornerRadius = ScreenX375(15);
    self.connectBtn.clipsToBounds = YES;
    [self addSubview:self.connectBtn];
    
    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(110) - 0.5, SCREEN_WIDTH - ScreenX375(26), 0.5)];
    line.image = [UIImage imageNamed:@"虚线"];
    [self addSubview:line];
}

- (void)setDesignListDataModel:(DesignListDataModel *)designListDataModel {
    _designListDataModel = designListDataModel;
    
    if (designListDataModel.person_img) {
        [self.headImage sd_setImageWithURL:[NSURL URLWithString:designListDataModel.person_img] placeholderImage:nil options:SDWebImageRetryFailed];
    }
    self.nameLabel.text = designListDataModel.name;
    CGFloat width = kGetStringWidth(designListDataModel.name, CGSizeMake(ScreenX375(150), ScreenX375(18)), Kfont(14));
    self.nameLabel.frame = CGRectMake(ScreenX375(104), ScreenX375(15), width + ScreenX375(5), ScreenX375(18));
    self.distanceLabel.text = [NSString stringWithFormat:@"%@元",designListDataModel.distance];
    self.distanceLabel.frame = CGRectMake(CGRectGetMaxX(self.nameLabel.frame) + ScreenX375(8), ScreenX375(17), ScreenX375(50), ScreenX375(15));
    _starView1.starScore = [designListDataModel.zongfen integerValue];
    _starView2.starScore = [designListDataModel.zongfen integerValue];
    _starView3.starScore = [designListDataModel.zongfen integerValue];
}

- (void)cellIsSelect:(BOOL)isSelect {
    if (isSelect) {
        self.nameLabel.textColor = ThemeColor;
    }else {
        self.nameLabel.textColor = REXADECIMALCOLOR(@"#333333");
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
